|
|
|
|
|
|
|
' Retrieve a collection containing ServiceStatus objects
Public Function EnumServicesStatus() As Collection
Dim res&
Dim lpServices As Long
Dim BytesNeeded As Long
Dim ServicesReturned As Long
Dim ResumeHandle As Long
Dim Buffer() As Byte
ReDim Buffer(512)
Dim x&
Dim CurrentOffset&
Dim c As New Collection
Dim s As ServiceStatus
Dim continue As Boolean
Do
' Load the buffer with as many services as possible
' We exclude driver services for now
res = intEnumServicesStatus(schandle, &H30, 3, VarPtr(Buffer(0)), _
UBound(Buffer()), BytesNeeded, ServicesReturned, ResumeHandle)
If res = 0 And Err.LastDllError = ERROR_MORE DATA Then
' Buffer couldn't hold all the services
continue = True
Else
continue = False
End If
For x = 1 To ServicesReturned
Set s = New ServiceStatus
' The ServiceStatus buffer does the actual extraction
Call s.ParseServiceInfo(Buffer(), CurrentOffset)
c.Add s
' 36 is the size of the ENUM_SERVICE_STATUS structure
CurrentOffset = CurrentOffset + 36
Next x
If continue Then
' Prepare for the next call
CurrentOffset = 0
ReDim Buffer(BytesNeeded)
End If
Loop While continue
Set EnumServicesStatus = c
End Function |
|
|
|
|
|